package com.ruoyi.activity.controller;

import com.ruoyi.activity.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 优惠券相关接口
 */
@RestController
@RequestMapping("/api/coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    /**
     * 用户抢券接口
     * @param userId 用户ID
     * @param activityId 活动ID
     * @return 抢券结果
     */
    @PostMapping("/grab") // 映射POST请求到/grab
    public String grabCoupon(@RequestParam Long userId, @RequestParam Long activityId) {
        // 调用CouponService的grabCoupon方法，执行抢券逻辑
        boolean result = couponService.grabCoupon(userId, activityId);
        // 根据抢券结果返回不同的字符串
        return result ? "抢券成功" : "抢券失败";
    }
} 